/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.security.pad;

import java.security.GeneralSecurityException;

/**
 * 
 * @author Administrator
 */
public class ISO9797M1 implements IPad {

	private byte[] padding = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

	@Override
	public byte[] pad(byte[] data) {
		int len = data.length % 8 == 0 ? data.length : (data.length / 8 + 1) * 8;
		byte[] dataTemp = new byte[len];
		System.arraycopy(data, 0, dataTemp, 0, data.length);
		if (dataTemp.length > data.length) {
			System.arraycopy(padding, 0, dataTemp, data.length, dataTemp.length - data.length);
		}
		return dataTemp;
	}

	@Override
	public byte[] removePad(byte[] data) throws GeneralSecurityException {
		return data.clone();
	}
}
